import net.minidev.json.JSONObject;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * @Author lzc
 * @Date 2022/3/18 10:56
 */
public class MapDemo {
    public static void main(String[] args) {
        String s = "a,c";
        List<String> columns = Arrays.asList(s.split(","));
        JSONObject obj = new JSONObject();
        obj.put("a", 1);
        obj.put("b", 2);
        obj.put("c", 3);
        obj.put("d", 4);
    
    
        Set<String> keys = obj.keySet();
        /*while (it.hasNext()) {
            String key = it.next();
            if (! columns.contains(key)) {
                it.remove();
            }
        }*/
    
        // 返回值是true删掉
        keys.removeIf(key -> !columns.contains(key));
        
        /*for (String key : keys) {
            if (!columns.contains(key)) {
                keys.remove(key);
            }
        }*/
    
        System.out.println(obj);
    }
}
